/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ca.trader.utils;

import javax.servlet.http.HttpServletRequest;

/**
 *
 * @author Ahsan
 */
public class URLUtils
{

	 public static String getMainWebpage(HttpServletRequest request)
	 {
		  return "http://" + getMainURL(request);
	 }

	 public static String getMainURL(HttpServletRequest request)
	 {
		  String host = request.getHeader("Host");

		  String pageURI = request.getRequestURI();

		  int indexOfSlash = pageURI.lastIndexOf('/');
		  if (indexOfSlash > 0)
		  {
			   pageURI = pageURI.substring(0, indexOfSlash);
		  }

		  return host + pageURI;
	 }

}
